/**********************************************************
 * Copyright © 2008，北京福富软件技术股份有限公司
 * All Rights Reserved.
 *
 * 文件名称： AttachmentViewResolver.java
 * 摘    要：
 *
 * 初始版本：1.0.0
 * 原 作 者：RUN
 * 完成日期：2009-5-11
 *
 * 当前版本：$LastChangedRevision$
 * 作    者：$LastChangedBy$
 * 完成日期：$LastChnagedDate$
 ************************************************************/
package aip.ui.attachment.web.spring;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.util.StringUtils;
import org.springframework.validation.BindException;

import com.googlecode.horncomb.web.spring.mvc.EventViewResolver;

/**
 * 根据附件类型获得转向页面
 * <p>
 * 负责人/principal: Daniel<br/>
 * 修改记录/revision:<br/>
 * 日期:<br/>
 * 修改人:<br/>
 * 修改说明:
 * @author RUN
 * @version $Id: codetemplates.xml 2007 2009-05-08 08:36:14Z shiw $
 */
public class AttachmentViewResolver implements EventViewResolver
{

    private Map<String, String> eventViewMap = null;
    private Map<String, String> attachmentTypeViewMap = null;

    @SuppressWarnings("unchecked")
    public Object getView(HttpServletRequest request, Object command,
            BindException errors, Map controlModel, String event)
    {
        String viewName = null;
        // 根据event获取转向view
        if (this.eventViewMap != null)
        {
            viewName = this.eventViewMap.get(event);
        }

        // 未定义指定的event转向，则根据文件的类型转向
        if (!StringUtils.hasText(viewName)
                && this.attachmentTypeViewMap != null)
        {
            if (command instanceof UploadForm)
            {
                UploadForm form = (UploadForm) command;
                String type = form.getAtchType();
                if (StringUtils.hasText(type))
                {
                    viewName = this.attachmentTypeViewMap.get(type);
                }
            }
        }
        return StringUtils.hasText(viewName) ? viewName : null;
    }

    /**
     * @param eventViewMap
     *        the eventViewMap to set
     */
    public void setEventViewMap(Map<String, String> eventViewMap)
    {
        this.eventViewMap = eventViewMap;
    }

    /**
     * @param attachmentTypeViewMap
     *        the attachmentTypeViewMap to set
     */
    public void setAttachmentTypeViewMap(
            Map<String, String> attachmentTypeViewMap)
    {
        this.attachmentTypeViewMap = attachmentTypeViewMap;
    }
}
